function ajaxAddNewick() {

    var stringField = $('#newickString');
    if( stringField.val() == '' ) { return; }

    var nameField = $('#newickName');
    if( nameField.val().trim() == '' ) { nameField.val('Untitled Tree'); }

    var commentField = $('#newickComment');
    if( commentField.val().trim() == '' ) { commentField.val( getCurrentDateTime() ); }

    $.ajax( { url: '/' + globals.applicationName + '/default/addNewick',
              type: "POST",
              data: { newickName: nameField.val(), newickString: stringField.val(), newickComment: commentField.val() },
              success: addNewickOnSuccess } );
}

function handleAddNewickResponse( p ) {
    if( p.response == 'parseError' ) { alert('Unable to parse your tree'); } else { displayTreeInfo( p.response, p.name, p.comment, 'sourceTrees' ); }
}

function ajaxDeleteNewick(id) {
    $.ajax( { url: '/' + globals.applicationName + '/default/delete',
              type: "POST",
              data: { id: id },
              success: removeUserTree(id) } );
}

function addNewickOnSuccess( id ) {

    handleAddNewickResponse( { response: id, name: $('#newickName').val(), comment: $('#newickComment').val() } );
    closeShadowbox();
}
